package com.koron.css2.clientCenter.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.mapper.UserInfoMapper;
import com.koron.css2.clientCenter.queryBean.UserInfoQueryBean;
import com.koron.css2.clientCenter.vo.UserPhoneListVO;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

public class UserPhoneList implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			UserInfoQueryBean uiqBean = JsonUtils.objectToPojo(req.getData(), UserInfoQueryBean.class);
			UserInfoMapper uiMapper = factory.getMapper(UserInfoMapper.class);
			PageHelper.startPage(uiqBean.getPage(), uiqBean.getPageCount());
			// 获取客户列表
			List<UserPhoneListVO> uiList = uiMapper.selectPhoneList(uiqBean);

			@SuppressWarnings("rawtypes")
			MessageBean<PageInfo> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", PageInfo.class);
			info.setData(new PageInfo<>(uiList));
			return info;
		} catch (Exception e) {
			logger.error("客户列表查询失败" + e.getMessage(), e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "查询失败", null);
		}
	}

}
